layui.use(['element', 'table', 'form', 'laydate'], function () {
        var $ = layui.$;
        var table = layui.table;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#test1',
            type: 'date',
            trigger: 'click'
        });
        var jsProduct = {}
        getTable(jsProduct);

        function getTable(jsProduct) {
            var userId = localStorage.getItem("createId");
            jsProduct.updateId = userId;
            $.ajax({
                url: '/courseTable/getLog',
                type: 'post',
                dataType: 'json',
                data: {
                    "userId": userId
                },
                success: function (data) {
                    tablereload(data.data);
                }
            });
        }

        function tablereload(date) {
            table.render({
                elem: '#table',
                data: date,
                title: '数据列表',
                limit: 10,
                id: 'table',
                toolbar: '#toptool',
                page: {
                    layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
                    first: "首页",
                    last: "尾页",
                },
                size: 'lg',
                cols: [[//定义列
                    {type: 'checkbox'},//复选框靠左
                    {field: 'logId', title: '序号', align: 'center'},
                    {field: 'userName', title: '管理员名称', align: 'center'},
                    {field: 'createDate', title: "操作时间", align: 'center'},
                    {
                        field: '',
                        title: "操作类型",
                        align: 'center',
                        templet: function (data) {
                            if (data.type == 2) {
                                var radio = '<p>添加</p>'
                            } else if (data.type == 3) {
                                var radio = '<p>删除</p>'
                            } else if (data.type == 4) {
                                var radio = '<p>编辑</p>'
                            } else if (data.type == 5) {
                                var radio = '<p>查看</p>'
                            } else {
                                var radio = '<p>未知</p>'
                            }
                            return radio;
                        }
                    },
                    {
                        field: '', title: "备注", align: 'center',
                        templet: function (data) {
                            if (data.remark != null) {
                                var radio = '<p>' + data.remark + '</p>'
                            } else {
                                var radio = '<p>无备注</p>'
                            }
                            return radio;
                        }
                    },
                    {
                        field: '', title: "操作", align: 'center', templet: function (data) {
                            return "<div>" +
                                "<a href='javascript:deleteoper(\"" + data.logId + "\");' style='color: #0EAA9E'>删除</a><br/>" +
                                "</div>";
                        }
                    },
                ]],
            });
        }

        //搜索
        search = function search() {
            var userName = $('input[name=userName]').val();
            var tableName = $('input[name=operationList]').val();
            var createDate = $('input[name=executionTime]').val();

            var classification = document.getElementById("operationType");
            var indexClass = classification.selectedIndex;
            var type = classification.options[indexClass].value;
            getTable2(userName, tableName, type, createDate);
        }
        //删除一条操作记录
        deleteoper = function deleteoper(id) {
            layer.confirm('是否确定删除此条数据', {
                icon: 3, title: '提示'
            }, function (index) {
                $.ajax({
                    url: '/courseTable/deleteLog',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        "id": id
                    },
                    success: function () {
                        layer.msg("删除成功");
                        getTable(jsProduct);
                    }
                });
            });
        }

        function getTable2(userName, tableName, type, createDate) {
            var userId = localStorage.getItem("createId");
            $.ajax({
                url: '/courseTable/getLog',
                type: 'post',
                dataType: 'json',
                data: {
                    "userName": userName,
                    "tableName": tableName,
                    "type": type,
                    "createDate": createDate,
                    "userId": userId
                },
                success: function (data) {
                    tablereload(data.data);
                }
            });
        }
    }
);

//刷新
function Refresh() {
    location.reload();
}

//跳转
function goBack() {
    parent.$('#quickHref').val('课程列表');
    parent.getQuick();
    return;
}